<?php
if (!function_exists('qiushi_styles')) {
    function qiushi_styles()
    {   
        $production=stripos($_SERVER['HTTP_HOST'],'hengha')!==false;
        if($production){
            wp_register_style('purecss-style', 'http://tuicool.qiniudn.com/cdn-pure.css', array(), null, 'all');
            wp_register_style('theme-style', 'http://tuicool.qiniudn.com/cdn-style.css', array(), null, 'all');
            wp_enqueue_script('jquery-script', 'http://lib.sinaapp.com/js/jquery/2.0.3/jquery-2.0.3.min.js', array(), null, true);
            wp_enqueue_script('plugins-script', 'http://tuicool.qiniudn.com/cdn-plugins.js', array(), null, true);
            wp_enqueue_script('moment-script', 'http://tuicool.qiniudn.com/cdn-moment-with-locales.min.js', array(), null, true);
            wp_register_script('qq-ta','http://tajs.qq.com/stats?sId=37096366',array(),null,true);
        }else{
            wp_register_style('purecss-style', get_stylesheet_directory_uri().'/css/pure.css', array(), null, 'all');
            wp_register_style('theme-style', get_stylesheet_directory_uri() . '/style.css', array(), null, 'all');
            wp_enqueue_script('jquery-script', get_template_directory_uri().'/js/jquery-2.1.1.min.js', array(), null, true);
            wp_enqueue_script('plugins-script', get_template_directory_uri().'/js/plugins.js', array(), null, true);
            wp_enqueue_script('moment-script', get_template_directory_uri().'/js/moment-with-locales.min.js', array(), null, true);
        }
        wp_enqueue_style('purecss-style');
        wp_enqueue_style('theme-style');
        
        wp_enqueue_script('app-script', get_template_directory_uri() . '/js/app.js', array(), null, true);
        if($production){
            wp_enqueue_script('qq-ta');
        }
    }
}
add_action('wp_enqueue_scripts', 'qiushi_styles');
if (!function_exists('qiushi_setup')) {
    function qiushi_setup()
    {
        register_nav_menus(array(
            'primary' => 'Top primary menu',
            'secondary' => 'Secondary menu in footer',
        ));
        
        add_theme_support( 'infinite-scroll', array(
            'type'           => 'scroll',
            'footer_widgets' => false,
            'container'      => 'content',
            'wrapper'        => true,
            'render'         => false,
            'posts_per_page' => false,
        ) );
    }
}
add_action('after_setup_theme', 'qiushi_setup');
function twentyfourteen_wp_title($title, $sep)
{
    global $paged, $page;

    if (is_feed()) {
        return $title;
    }
    $title .= get_bloginfo('name', 'display');

    $site_description = get_bloginfo('description', 'display');
    if ($site_description && (is_home() || is_front_page())) {
        $title = "$title $sep $site_description";
    }

    if ($paged >= 2 || $page >= 2) {
        $title = "$title $sep " . sprintf(__('Page %s', 'twentyfourteen'), max($paged, $page));
    }

    return $title;
}

add_filter('wp_title', 'twentyfourteen_wp_title', 10, 2);
if ( ! function_exists( 'joke_paging_nav' ) ) :
function joke_paging_nav() {
    if ( $GLOBALS['wp_query']->max_num_pages < 2 ) {
        return;
    }

    $paged        = get_query_var( 'paged' ) ? intval( get_query_var( 'paged' ) ) : 1;
    $pagenum_link = html_entity_decode( get_pagenum_link() );
    $query_args   = array();
    $url_parts    = explode( '?', $pagenum_link );

    if ( isset( $url_parts[1] ) ) {
        wp_parse_str( $url_parts[1], $query_args );
    }

    $pagenum_link = remove_query_arg( array_keys( $query_args ), $pagenum_link );
    $pagenum_link = trailingslashit( $pagenum_link ) . '%_%';

    $format  = $GLOBALS['wp_rewrite']->using_index_permalinks() && ! strpos( $pagenum_link, 'index.php' ) ? 'index.php/' : '';
    $format .= $GLOBALS['wp_rewrite']->using_permalinks() ? user_trailingslashit( 'page/%#%', 'paged' ) : '?paged=%#%';

    // Set up paginated links.
    $links = paginate_links( array(
        'base'     => $pagenum_link,
        'format'   => $format,
        'total'    => $GLOBALS['wp_query']->max_num_pages,
        'current'  => $paged,
        'mid_size' => 1,
        'type'=>'list',
        'add_args' => array_map( 'urlencode', $query_args ),
        'prev_text' => '上一页',
        'next_text' => '下一页',
    ) );

    if ( $links ) :

    ?>
    <nav class="navigation paging-navigation pure-u-1" role="navigation">
        <?php echo $links; ?>
    </nav>
    <?php
    endif;
}
endif;
